﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Content
{
#if NETFX_CORE || WINDOWS_UWP
    using Windows.Storage;
    using Windows.Storage.Streams;
    using ICSharpCode.SharpZipLib.Zip;
#endif


    using System.Threading.Tasks;

    public sealed class ContentFactory
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="noteBookName"></param>
        /// <returns></returns>
        public static Notebook CreateNewNoteBook(string noteBookName)
        {
            // TODO
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static Notebook LoadNoteBook(string fileName)
        {
            // TODO:
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="book"></param>
        /// <param name="pageName"></param>
        /// <returns></returns>
        public static Page CreateNewPage(Notebook book, string pageName)
        {
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="notebook"></param>
        /// <returns></returns>
        public static IEnumerable<Page> LoadPages(Notebook notebook)
        {
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        /// <param name="sectionName"></param>
        /// <returns></returns>
        public static Section CreateNewSection(Page page, string sectionName)
        {
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        public static Section CreateNewSection(Page page)
        {
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public static IEnumerable<Section> LoadSection(Page page)
        {
            return null;
        }

        #region Low Level Storage API

        // Low Level Storage API
        // the API implement by ICSharpCode.SharpZipLib.Zip
        // this API contains four-part 
        // 1) save or load notebooks which contain text
        // 2) save or load static resource
        // 3) save or load version control information
        // 4) save or load auto-save

        // we are considering that use lazyload tech to reduce memory cost

        // 下面为低层次的存储API，主要实现四部分内容的存取功能
        // 1) 笔记本文本内容的存取
        // 2) 静态资源的存取
        // 3) 版本控制信息的存取
        // 4) 因为程序意外崩溃而保存的内容
        //
        // 下面的API设计我们优先考虑LazyLoad以及异步加载
        // 

        /// <summary>
        /// 打开ANB(AcorisNotebook)文件
        /// </summary>
        /// <param name="fileName">指定文件所在的详细位置</param>
        /// <returns>返回文件加载的ZipFile文件</returns>
        async static Task<ZipFile> LoadANBFile(string fileName)
        {
#if NETFX_CORE || WINDOWS_UWP
            if (!File.Exists(fileName)) {
                throw new FileNotFoundException("指定的文件无法打开");
            }
            var storageFile = await StorageFile.GetFileFromPathAsync(fileName);
            var uapStream = await storageFile.OpenAsync( FileAccessMode.ReadWrite);

            return null;
#elif NETFX_DESKTOP || WINDOWS_WPF
#endif
            return null;
        }

#if NETFX_CORE || WINDOWS_UWP
        static Stream UapStream2Stream(IRandomAccessStream stream)
        {
            return stream.AsStream();
        }
#endif
        #endregion


    }
}
